#include "comm.hpp"

extern Log log;

int main()
{
    //创建共享内存
    int shmid = creat_share_memory();
    //挂接共享内存
    char* shmaddr = load_share_memory(shmid);

    struct shmid_ds shmod;
    //进程通信代码
    while (true)
    {
        shmctl(shmid, IPC_STAT, &shmod);
        std::cout << "shm size: " << shmod.shm_segsz << std::endl;
        std::cout << "shm nattch: " << shmod.shm_nattch << std::endl;
        printf("shm mode: o%o\n", shmod.shm_perm.mode);
        printf("shm key: 0x%x\n", shmod.shm_perm.__key);
        std::cout << std::endl;
        sleep(1);
    }

    //去关联共享内存
    unload_share_memory(shmaddr);
    //删除共享内存
    delete_share_memory(shmid);

    return 0;
}